package com.training.bt.controller;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.training.bt.entity.User;
import com.training.bt.entity.UserPoint;
import com.training.bt.mapper.UserPointMapper;
import com.training.bt.security.util.SecurityUtils;

import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/point")
public class PointController {
    private final UserPointMapper userPointMapper;

    @GetMapping("/getPoint")
    public ResponseEntity<UserPoint> getPoint() {
        User user = SecurityUtils.getCurrentUser();
        LambdaQueryWrapper<UserPoint> wrapper = new LambdaQueryWrapper<UserPoint>()
                .eq(UserPoint::getUserId, user.getId());
        UserPoint userPoint = userPointMapper.selectOne(wrapper);
        return ResponseEntity.ok(userPoint);
    }
}
